package com.adee.primary.t01_arr;

/**
 * 加一
 */
public class T007 {
    public static void main(String[] args) {

    }

    public int[] plusOne(int[] digits) {
        int carry = 1;
        int i = digits.length-1;
        while(i >= 0) {
            int curr = digits[i] + carry;
            if(curr == 10) {
                digits[i] = 0;
                carry = 1;
                --i;
            }else {
                digits[i] = curr;
                carry = 0;
                break;
            }
        }
        if(carry == 1) {
            int[] arr = new int[digits.length+1];
            arr[0] = 1;
            System.arraycopy(digits, 0, arr, 1, digits.length);
            return arr;
        }
        return digits;
    }
}
